<?php

namespace App\Kids\Basic;

use p5\objects\StringUtils;
use ReflectionClass;

/**
 * Created by PhpStorm.
 * User: simon
 * Date: 2016/9/3
 * Time: 18:47
 */
class BaseBean
{

    public function toArray()
    {
        $ref = new ReflectionClass($this);
        $methods = $ref->getMethods();
        $properties = [];
        foreach ($methods as $method) {
            $name = $method->name;
            $len = strlen($name);
            if ($len < 3) {
                continue;
            }
            $prefix = substr($name, 0, 3);
            if ($prefix != "get") {
                continue;
            }
            $temp = StringUtils::underline_case($name);
            $property = substr($temp, 4);
            $value = $this->$name();
            $properties[$property] = $value;
        }
        // print_r($properties);
        return $properties;
    }
}